#pragma once
#include <list>
#include <boost/tokenizer.hpp>

namespace html { namespace dom
{
  using namespace boost;

  struct nodes;
  struct node;

  /// @brief selector that stores one or more CSS selector criterions
  struct selector 
    : vector<criteria> {

    /// @brief initialize selector with a CSS-like selector string
    selector(const char* _select) {
      parse(_select);
    }
    /// @brief initialize selector with a CSS-like selector string
    selector(const string& _select) {
      parse(_select);
    }
    /// @brief set selector to a CSS-like selector string
    void parse(const string& _select) {
      // clear previous content
      clear();
      // search string for space delimiters
      tokenizer<char_separator<char> > tok(_select,char_separator<char>(" "));
      for (tokenizer<char_separator<char> >::iterator it=tok.begin(); it!=tok.end(); ++it)
        push_back(criteria(*it));
    }
    /// @brief select all descendants from a given node that match the
    /// stored criterions and store the result in _out. the order of the
    /// found nodes in _out will be the same as in the searched node
    inline void select (node _node, nodes& _out) const;
    /// @brief select all descendants from all nodes in _in that match the
    /// criterions which itCriteria is pointing to and store the result in _out
    inline void select (const_iterator itCriteria, const nodes_data& _in, nodes& _out ) const;
  };
} }
